# coding=utf-8
"""
Author: Mr.夏末
@Function: 钩子模块
"""
import time
import pytest
from class11.webkeys import Web

web = None

# 会话级别
@pytest.fixture(scope='session')
def getweb():
    """获取关键字对象的钩子函数"""
    global web
    web = Web()
    # 判断没有打开浏览器，就打开
    if not web.driver:
        web.openbrowser()
    print('************************跑了几次***************************')
    yield web

# 用例级别
@pytest.fixture(scope='function')
def logins(getweb):
    """确认登录"""
    # 判断没有打开浏览器，就打开
    web = getweb
    web.get_url("http://47.105.110.138:8000/index.php/Home/user/login.html")
    title = web.driver.title
    print("-------------------------------------------------")
    # 如果有登录态
    if title.startswith('登录'):
        web.input('username', '2529085125@qq.com')
        web.input('//*[@id="password"]', '123456')
        web.input('//*[@id="verify_code"]', '1234')
        web.click('//a[contains(text(),"登")]')
    time.sleep(1)


